/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mycompany.managed;

import com.mycompany.entity.PomodoroUser;
import com.mycompany.session.UserSessionBean;
import java.security.Principal;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;


@ManagedBean
@SessionScoped
public class UserMB {
    
    @EJB
    private UserSessionBean userSessionBean;
    
    private PomodoroUser pomodoroUser;
    
    public PomodoroUser getLoggedUser() {
        
        if (pomodoroUser==null) {
            Principal principal = FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal();
            if (principal != null) {
                pomodoroUser = userSessionBean.findByUsername(principal.getName()); //TODO 
            }
        }
        
        return pomodoroUser;
    }
}
